import { JupiterTag, JupiterTagQuery } from '../types/tagTypes';
import request from 'utils/request';

// 获取标签列表
export const fetchTagList = (params: JupiterTagQuery) => {
  return request.post('/tags/page', params);
};

// 获取所有标签
export const fetchAllTags = () => {
  return request.get('/tags');
};

// 根据UUID获取标签
export const fetchTagById = (uuid: string) => {
  return request.get(`/tags/${uuid}`);
};

// 创建标签
export const createTag = (data: Partial<JupiterTag>) => {
  return request.post('/tags', data);
};

// 更新标签
export const updateTag = (uuid: string, data: Partial<JupiterTag>) => {
  return request.put(`/tags/${uuid}`, data);
};

// 删除标签
export const deleteTag = (uuid: string) => {
  return request.delete(`/tags/${uuid}`);
};

// 批量删除标签
export const batchDeleteTags = (uuids: string[]) => {
  return request.delete('/tags/batch', { data: { uuids } });
};

// 获取激活状态的标签列表
export const fetchActiveTags = () => {
  return request.get('/tags/active');
};

// 获取标签的文章数量
export const fetchTagArticleCount = (uuid: string) => {
  return request.get(`/tags/${uuid}/article-count`);
};

// 更新标签排序
export const updateTagSort = (uuid: string, sortOrder: number) => {
  return request.put(`/tags/${uuid}/sort`, { sortOrder });
};

// 根据颜色获取标签列表
export const fetchTagsByColor = (color: string) => {
  return request.get(`/tags/color/${color}`);
};

// 获取热门标签
export const fetchPopularTags = (limit: number = 20) => {
  return request.get(`/tags/popular?limit=${limit}`);
};
